package com.example.yichuangyun.utils.producttreelist;

import com.example.yichuangyun.R;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 意向产品
 */
public class ProductNodeModel implements Serializable {
    private String id;
    private String productid;
    private String title;
    private int type;
    private String poolid;
    private List<ProductNodeModel> children = new ArrayList<>();

    /**
     * 设置开启 关闭的图片
     */
    private int iconExpand = R.mipmap.icon_up, iconNoExpand = R.mipmap.icon_down;

    /**
     * 是否展开
     */
    private boolean isExpand = false;

    /**
     * 是否被checked选中
     */
    private boolean isChecked;

    private int icon = -1;

    /**
     * 父Node
     */
    private ProductNodeModel parent;

    /**
     * 根节点pId为0
     */
    private String parentId;

    private int flag;

    private String parentProductId;

    /**
     * 商机来源--label来源名称
     */
    private String label;

    /**
     * 使用状态：1不可用，0可用
     */
    private int useState;

    public ProductNodeModel(String title, String id, String parentId, int useState) {
        super();
        this.id = id;
        this.parentId = parentId;
        this.title = title;
        this.useState = useState;
    }

    public ProductNodeModel(String title, String id) {
        super();
        this.id = id;
        this.title = title;
    }

//    public ProductNodeModel(String title, String id, String parentId, String productId, String poolId, int type, int flag, String parentProductId) {
//        super();
//        this.id = id;
//        this.parentId = parentId;
//        this.productid = productId;
//        this.poolid = poolId;
//        this.title = title;
//        this.type = type;
//        this.flag = flag;
//        this.parentProductId = parentProductId;
//    }

    public ProductNodeModel(String title, String id, String parentId, String productId, String poolId, int type, int flag, String parentProductId) {
        super();
        this.id = id;
        this.parentId = parentId;
        this.productid = productId;
        this.poolid = poolId;
        this.title = title;
        this.type = type;
        this.flag = flag;
        this.parentProductId = parentProductId;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getProductid() {
        return productid;
    }

    public void setProductid(String productid) {
        this.productid = productid;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getPoolid() {
        return poolid;
    }

    public void setPoolid(String poolid) {
        this.poolid = poolid;
    }

    public List<ProductNodeModel> getChildren() {
        return children;
    }

    public void setChildren(List<ProductNodeModel> children) {
        this.children = children;
    }

    public int getIconExpand() {
        return iconExpand;
    }

    public void setIconExpand(int iconExpand) {
        this.iconExpand = iconExpand;
    }

    public int getIconNoExpand() {
        return iconNoExpand;
    }

    public void setIconNoExpand(int iconNoExpand) {
        this.iconNoExpand = iconNoExpand;
    }

    public boolean isExpand() {
        return isExpand;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public int getIcon() {
        return icon;
    }

    public void setIcon(int icon) {
        this.icon = icon;
    }

    public ProductNodeModel getParent() {
        return parent;
    }

    public void setParent(ProductNodeModel parent) {
        this.parent = parent;
    }

    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public String getParentProductId() {
        return parentProductId;
    }

    public void setParentProductId(String parentProductId) {
        this.parentProductId = parentProductId;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public int getUseState() {
        return useState;
    }

    public void setUseState(int useState) {
        this.useState = useState;
    }

    /**
     * 是否为跟节点
     */
    public boolean isRoot() {
        return parent == null;
    }

    /**
     * 判断父节点是否展开
     */
    public boolean isParentExpand() {
        if (parent == null)
            return false;
        return parent.isExpand();
    }

    /**
     * 是否是叶子节点
     */
    public boolean isLeaf() {
        return children.size() == 0;
    }

    /**
     * 获取level
     */
    public int getLevel() {
        return parent == null ? 0 : parent.getLevel() + 1;
    }

    /**
     * 设置展开
     */
    public void setExpand(boolean isExpand) {
        this.isExpand = isExpand;
        if (!isExpand) {
            for (ProductNodeModel node : children) {
                node.setExpand(false);
            }
        }
    }
}
